//
//  IManager+RegisterRequest.m
//  RocketProject
//
//  Created by chen jiedan on 13-9-10.
//  Copyright (c) 2013年 Rocket. All rights reserved.
//

#import "IManager+RegisterRequest.h"
#import "NSString+NSString_Ex_.h"
#import "RequestUtlity.h"
#import "FrameworkRelativeDefines.h"
#import "RCPhoneVerifyDataModel.h"
#import "TravelException.h"

@implementation IManager (RegisterRequest)

- (int64_t) requestRegVerifyCodePhoneNumber:(NSString *)phoneNumber withDelegate:(id<IManagerDelegate>)delegate
{
    if ([NSString stringIsNullOrEmpty:phoneNumber]) {
        return kInvalidRequestId;
    }
    // 异步获取数据
    NSString *urlSuffix = [NSString stringWithFormat:kRCPhoneRegVerfiyPrefix,phoneNumber];
    
    NSString *url = [RequestUtlity getFormattedUrl:urlSuffix];    
    
    return [[IDataProvider sharedInstance] asyncFetchDataWithUserInfo:url
                                                             userInfo:nil
                                                      withCachePolicy:IDataCachePolicyLocalFileAndNetwork
                                                   withDataParseClass:[RCPhoneVerifyDataModel class]
                                                     withDataDelegate:delegate];

}


-(int64_t)requestPhoneNumber:(NSString *)phoneNumber withVerifyCode:(NSString*)code withDelegate:(id<IManagerDelegate>)delegate
{
    if ([NSString stringIsNullOrEmpty:phoneNumber]) {
        return kInvalidRequestId;
    }
    // 异步获取数据
    NSString *urlSuffix = [NSString stringWithFormat:kRCPhoneSubmitVerifyPrefix,phoneNumber,code];
    
    NSString *url = [RequestUtlity getFormattedUrl:urlSuffix];
//    NSDictionary *userInfo = [[NSDictionary alloc] initWithObjects:[NSArray arrayWithObject:@"submitCheckCode"] forKeys:[NSArray arrayWithObject:@"FakeJson"]];

    return [[IDataProvider sharedInstance] asyncFetchDataWithUserInfo:url
                                                             userInfo:nil
                                                      withCachePolicy:IDataCachePolicyLocalFileAndNetwork
                                                   withDataParseClass:[RCPhoneSubmitCheckCodeDataModel class]
                                                     withDataDelegate:delegate];
    
}



-(int64_t)requestEmail:(NSString *)mail withUserName:(NSString*)uName withPassword:(NSString *)password withPhoneType:(BOOL)isPhoneReg withDelegate:(id<IManagerDelegate>)delegate
{
    if ([NSString stringIsNullOrEmpty:mail] || [NSString stringIsNullOrEmpty:uName] || [NSString stringIsNullOrEmpty:password] ) {
        return kInvalidRequestId;
    }
    // 异步获取数据
    
    NSString *url = [RequestUtlity getFormattedUrl:kRCFulfillNameWithPrefix];
    NSMutableDictionary *postValue = [NSMutableDictionary dictionary];
    if (isPhoneReg) {
        [postValue setObject:mail forKey:@"phone" withDefaultValue:@""];
        [postValue setObject:@"phone" forKey:@"type" withDefaultValue:@""];
    }else{
        [postValue setObject:mail forKey:@"email" withDefaultValue:@""];
        [postValue setObject:@"email" forKey:@"type" withDefaultValue:@""];

    }
    [postValue setObject:uName forKey:@"username" withDefaultValue:@""];
    [postValue setObject:password forKey:@"password" withDefaultValue:@""];
//    [postValue setObject:@"PhoneRegFulfillName" forKey:@"FakeJson" withDefaultValue:@""];
    return [[IDataProvider sharedInstance] asyncPostData:url postValues:postValue postDataList:nil userInfo:nil withDataParseClass:[RCEmailRegDataModel class] withDataDelegate:delegate];
//    return [[IDataProvider sharedInstance] asyncFetchDataWithUserInfo:url
//                                                             userInfo:postValue
//                                                      withCachePolicy:IDataCachePolicyLocalFileAndNetwork
//                                                   withDataParseClass:[RCEmailRegDataModel class]
//                                                     withDataDelegate:delegate];
}
@end



